home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2002 #11
/
Amiga Plus CD - 2002 - No. 11.iso
/
Tools
/
ShareMailGiftware
/
Frogger
/
plugins_src
/
p_ac3
/
ac3.c
< prev
next >
Wrap
C/C++ Source or Header
|
2002-10-28
|
2KB
|
122 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "inttypes.h"
#include "a52.h"
#include "ac3.h"
#include "mm_accel.h"
static __inline int16_t convert (int32_t i)
{
if (i > 0x43c07fff)
return 32767;
else if (i < 0x43bf8000)
return -32768;
else
return i - 0x43c00000;
}
static __inline void float_to_int (float * _f, int16_t * s16)
{
int i;
int32_t * f = (int32_t *) _f;
s16 -= 1;
for (i = 0; i < 256; i++)
{
*(++s16) = convert (f[i]);
*(++s16) = convert (f[i+256]);
}
}
void decodeAC3(void *handle, unsigned char *start, unsigned char *end,unsigned char *out, int *outsize,int *freq)
{
a52_state_t * state = handle;
static uint8_t buf[3840];
static uint8_t * bufptr = buf;
static uint8_t * bufpos = buf + 7;
static int sample_rate;
static int flags;
int bit_rate;
int len;
*outsize = 0;
while (1)
{
len = end - start;
if (!len)
break;
if (len > bufpos - bufptr)
len = bufpos - bufptr;
memcpy (bufptr, start, len);
bufptr += len;
start += len;
if (bufptr == bufpos)
{
if (bufpos == buf + 7)
{
int length;
length = a52_syncinfo (buf, &flags, &sample_rate, &bit_rate);
if (!length)
{
for (bufptr = buf; bufptr < buf + 6; bufptr++)
bufptr[0] = bufptr[1];
continue;
}
bufpos = buf + length;
}
else
{
sample_t level, bias;
int i;
flags = A52_STEREO | A52_ADJUST_LEVEL;
level = 4;
bias = 384;
if (a52_frame (state, buf, &flags, &level, bias))
goto error;
a52_dynrng (state, NULL, NULL);
for (i = 0; i < 6; i++)
{
if (a52_block (state))
goto error;
float_to_int (a52_samples (state), (int16_t *)out);
out += (256*2*2); //256 samples, two channels, two bytes per sample
*outsize += (256*2*2);
}
bufptr = buf;
bufpos = buf + 7;
continue;
error:
bufptr = buf;
bufpos = buf + 7;
}
}
}
if(freq)
*freq = sample_rate;
}
void *initAC3(void)
{
return a52_init (MM_ACCEL_DJBFFT);
}
void closeAC3(void *handle)
{
if(handle)
a52_free (handle);
}